import "virtual:uno.css";
import "virtual:svg-icons-register";
import "@soybeanjs/vue-materials/dist/style.css";
import "./styles/css/global.css";
import { createApp } from "vue";
import { setupStore } from "./store";
import { setupDirectives } from "./directives";
import { setupRouter } from "./router";
import { initViews } from "./views";
import App from "./App.vue";
import AppLoading from "./components/app/app-loading.vue";

const setupApp = async () => {
  try {
    const appLoading = createApp(AppLoading);
    // 注册pinia
    setupStore(appLoading);
    // 挂载加载页面
    appLoading.mount("#app");

    const app = createApp(App);

    // 注册pinia
    setupStore(app);

    // 注册自定义指令
    setupDirectives(app);

    // 加载页面组件，便于注册router
    await initViews();

    // 注册router
    await setupRouter(app);

    appLoading.unmount();

    app.mount("#app");
  } catch (error) {
    window.$message?.error("系统异常");
    console.error(error);
  }
};

setupApp();
